< previous page page_23 next page >

Page 23
PSet Step (x, y), color
Step
If you include the Step keyword, the X and Y coordinates are relative to the end of your last drawing command.
x, y
The coordinates of the point you want to color.
color
The color for the point.

Because PSet sets a single pixel, it is easiest to use when the drawing object's ScaleMode is vbPixels. Then the coordinates you send to PSet exactly match those drawn on the screen. If you use some other ScaleMode, such as vbTwips, you need to compute the location of the pixel you want to draw. If you are not careful, you may have trouble setting each pixel exactly once.
For example, the following code sets every pixel in the picture box picBlack to the color black.
e10a6a0a59f035e870d90cca05b85fce.gif
Dim X As Single 
Dim Y As Single 

    ' Make all the pixels black.
    For X = 0 To picMirror.ScaleWidth
        For Y = 0 To picMirror.ScaleHeight
            picBlack.PSet (X, Y), vbBlack
        Next Y
    Next X
This code works as you would expect if the control's ScaleMode is vbPixels. If the control's ScaleMode is vbTwips, however, the code takes far longer than it should. Because twips are relatively small, there are several twips per pixel. A typical monitor might display 72 pixels per logical inch. There are 1440 twips per logical inch, so the monitor has 20 twips per pixel. As X moves from 0 to picBlack.ScaleWidth, it sets the color of each pixel 20 times, so the code takes roughly 20 times as long as it should.
0023-01.jpg
Figure 1.11
Example program PaintPic demonstrates PaintPicture opcodes.

 
< previous page page_23 next page >